$OpenBSD: patch-wmcube_wmcube_c,v 1.4 2014/09/17 14:34:39 espie Exp $
--- wmcube/wmcube.c.orig	Mon Oct 23 22:11:47 2000
+++ wmcube/wmcube.c	Wed Sep 17 16:33:06 2014
@@ -858,6 +858,10 @@ void print_help() {
 	printf("  -n  : exclude \"nice\" processes. (default OFF)\n");
 #endif
 
+#ifdef OPENBSD
+	printf("  -n  : exclude \"nice\" processes. (default OFF)\n");
+#endif
+
 	printf("  -b  : draw the cube in a brighter color. (default OFF)\n");
 	printf("  -i  : invert cube speed. (default OFF)\n");
 	printf("  -p  : do not display cpu-load (default OFF)\n");
@@ -913,7 +917,7 @@ int loadobj(char *filename) {
 		exit(0);
 	}
 
-	fscanf(fp,"%s",tmp);
+	fscanf(fp,"%63s",tmp);
 	
 	if (strcmp(tmp,"WMCUBE_COORDINATES") != 0) { 
 		printf("\nError in objectfile: it must start with WMCUBE_COORDINATES\n\n");
@@ -921,7 +925,7 @@ int loadobj(char *filename) {
 		exit(0);
 	}
 
-	fscanf(fp,"%s",tmp);
+	fscanf(fp,"%63s",tmp);
 	counter = atoi(tmp);
 
 	while ((strcmp(tmp,"WMCUBE_LINES") != 0) && (strcmp(tmp,"WMCUBE_PLANES") != 0)) {		
@@ -938,7 +942,7 @@ int loadobj(char *filename) {
 			fclose(fp);
 			exit(0);
 		}
-		fscanf(fp,"%s",tmp);
+		fscanf(fp,"%63s",tmp);
 
 		if (feof(fp)) {
 			printf("\nError in objectfile: you must have a section WMCUBE_LINES or WMCUBE_PLANES\n\n");
@@ -1272,17 +1276,45 @@ int calc_cpu_total() {
 }
 
 #elif defined OPENBSD
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/sched.h>
 
 int init_calc_cpu()
 {
 	return 0;
 }
 
-int calc_cpu_total() {
-        double avenrun[3];
-        
-        (void) getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0]));
-        return(((5.0*avenrun[0] + 0.5) > 50) ? 50 : (5.0*avenrun[0] + 0.5))*2;
+int calc_cpu_total()
+{
+	int total, used, t=0;
+	static int previous_total = 0, previous_used = 0;
+	int cpu,nice,system,idle;
+	unsigned long int cpu_time[CPUSTATES];
+
+	int mib[2];
+	size_t size;
+
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_CPTIME;
+	size = sizeof (cpu_time);
+
+	if (sysctl(mib, 2, &cpu_time, &size, NULL, 0) < 0)
+		return 0;
+
+	cpu = cpu_time[CP_USER];
+	nice = cpu_time[CP_NICE];
+	system = cpu_time[CP_SYS];
+	idle = cpu_time[CP_IDLE];
+
+	used = cpu + system + use_nice*nice;
+	total = used + idle + (1-use_nice)*nice;
+
+	t = 100 * (double)(used - previous_used) / (double)(total - previous_total);
+	previous_total = total;
+	previous_used = used;
+
+	return t;
 }
 
 
